﻿using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.Routing;

namespace ZSoft.Telegram.UI.Web.Infrastructure.AppEvents.Begin_Request
{

    public class SetThreadCulture: IAppEventHandler
    {
        public AppEventType EventType
        {
            get { return AppEventType.Application_BeginRequest; }
        }

        public void Execute()
        {
            HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
            RouteData routeData = RouteTable.Routes.GetRouteData(currentContext);
            var info = routeData.Values["Culture"].ToString();
            Thread.CurrentThread.CurrentCulture = new CultureInfo(info);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(info);
        }
    }
}